<?php

namespace App\Admin\Controllers;

use App\Models\Coupon;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Controllers\AdminController;

class CouponsController extends AdminController
{
    protected $title = '卡卷管理';
    
    protected function grid()
    {
        $grid = new Grid(new Coupon());
	
	    $grid->disableExport();
	    
	    $grid->column('name', '卡卷名称');
	    $grid->column('coupon_category', '卡卷类型')->select(config('site.coupon'));
	    $grid->column('full_price', '满减金额');
	    $grid->column('decrement_price', '优惠金额');
	    $grid->column('created_at', '创建时间')->display(function () {
	    	return $this->created_at->toDatetimeString();
	    });
        return $grid;
    }
    
    protected function detail($id)
    {
        $show = new Show(BlindBoxCategory::findOrFail($id));



        return $show;
    }
    
    protected function form()
    {
        $form = new Form(new Coupon());
	   	$this->formCategory($form);
	    $form->text('name', '盲盒分类名称');
	   	$form->currency('full_price', '满减金额')->symbol('￥')->default(0);
 		$form->currency('decrement_price', '优惠金额')->symbol('￥')->default(0);
 		$form->text('day', '几天后过期');
        return $form;
    }

    protected function formCategory(Form $form)
    {
	    $form->select('coupon_category', '卡卷类型')
		    ->options(config('site.coupon'))
		    ->rules(['nullable', function ($attribute, $value, $fail) {
			    
			    return true;
		    }]);
    }
}
